<template>
<!-- 费用总和 -->
  <section class="printOrder ">
    <div class="print_box print_dl_box">
      <h3 style="text-align:center;">{{hospital}}</h3>
      <dl>
        <dt>{{detail.patientInfo.name}}    <span>{{detail.hpDepartment.deptName}}</span></dt>
        <dd  v-if="jc_total!=0">检查收费   <span class="print_dl_space">￥{{jc_total | changeMoneyToTwo}}</span></dd>
        <dd  v-if="zl_total!=0">治疗收费   <span class="print_dl_space">￥{{zl_total | changeMoneyToTwo}}</span></dd>
        <dd  v-if="cf_total!=0">处方收费   <span class="print_dl_space">￥{{cf_total | changeMoneyToTwo}}</span></dd>
        <dd  v-if="zzl_total!=0">诊疗收费  <span class="print_dl_space">￥{{zzl_total | changeMoneyToTwo}}</span></dd>
        <dd  v-if="cl_total!=0">材料收费   <span class="print_dl_space">￥{{cl_total | changeMoneyToTwo}}</span></dd>
        <dd  v-if="qt_total!=0">其他收费   <span class="print_dl_space">￥{{qt_total | changeMoneyToTwo}}</span></dd>
      </dl>
      <span style="margin-top:10px;display:inline-block;">合计：<span class="print_dl_space">￥{{total | changeMoneyToTwo}}</span></span>
      <div class="footer_box print_footer_box">
        <span>{{detail.hpMember.memberName}}</span>
        <span class="print_dl_space">{{time}}</span>
      </div>
    </div>
  </section>
</template>
<script>
export default {
  props: ["orderId", "name","total","detail"],
  data() {
    return {
      hospital:'',
      itemList: [],
      dwList: [],
      discountEnum:[],
      jc_total:0,
      zl_total:0,
      cf_total:0,
      zzl_total:0,
      cl_total:0,
      qt_total:0,
      time:''
    };
  },
  created(){
     this.time=this.getNewDate()
  },
  mounted() {
    // this.getHospital();
    // this.getBasic();
    let th=this;
    let fn= async function() {
      th.discountEnum = await th.getCommonConfigByKey("会员折扣关联")
      th.hospital=th.adminUser.hospitalName
      th.getOrderItem();
    };
    fn();
  },
  methods: {
    getOrderItem() {
      let th = this;
      th.showLoading()
      th.$api.getOrderItem({ orderId: th.orderId }).then(res => {
        if (res.executed) {
          let item = res.dataBody.pageInfo.list;
          let total = 0;
          // 2处方 3治疗 4实验室检查 5:辅助检查 6：材料费 7：其他收费 8:西药 9:中药 10:零售药
          let jc_total=0;//检查
          let zl_total=0;//治疗
          let cf_total=0;//处方
          let zzl_total=0//诊疗
          let cl_total=0;
          let qt_total=0
          for (let i = 0; i < item.length; i++) {
            item[i].realityMoney = Number(item[i].realityMoney).toFixed(2);
            item[i].discountMoney = 0;
            let typeId=th.getDiscounts(item[i].source);
            if(typeId==2){
              jc_total+=Number(item[i].realityMoney)
            }else if(typeId==3){
              zl_total+=Number(item[i].realityMoney)
            }else if(typeId==4){
              cf_total+=Number(item[i].realityMoney)
            }else if(typeId==5){
              zzl_total+=Number(item[i].realityMoney)
            }else if(typeId==6){
              cl_total+=Number(item[i].realityMoney)
            }else{
              qt_total+=Number(item[i].realityMoney)
            }
          }
          th.jc_total=jc_total
          th.zl_total=zl_total
          th.cf_total=cf_total
          th.zzl_total=zzl_total
          th.cl_total=cl_total
          th.qt_total=qt_total
          setTimeout(function() {
            window.document.body.innerHTML = document.getElementsByClassName(
              "printOrder"
            )[0].innerHTML;
            th.showLoading(false);
            window.print();
            window.location.reload();
          }, 1000);
        }
      });
    },
    //获取折扣
    getDiscounts(source) {
      let th = this;
      let value = 1;
      let typeId;
      //获取source属于什么分类
      for (let i = 0; i < th.discountEnum.length; i++) {
        let data = th.discountEnum[i];
        let index = data.desc.indexOf(source + "");
        if (index != -1) {
          typeId = data.id;
          break;
        }
      }
      return typeId;
    },
    getBasic() {
      let th = this;
      th.getCommonConfigByKey("药品剂量单位").then(res => {
        th.dwList = res;
      });
    }
  }
};
</script>